General Step to Dockerizing a Project
- Tools
- Create a
dockerfile
- Create
.dockerignore
to make docker ignore some files such asnode_modules
- By this step you can build and run the container
- If multiple docker need to be coupled together add
docker-compose.yml
- By this step you can run multiple containers
- 6. docker compose
How to Run a Docker Project
- Build the image
docker image build -t zekaryas/projectName .
#docker image build -t{tag or name} name_of_the_image .{where the dockerfile is}
# . means in the current directory
#list images we have
docker image ls
- Run the image
docker container run -d -p 80:8080 zekaryas/projectName
# -d = detached: run in the background
# -p = port mapping public_port:container_exposed_port
# list containers and their information {id, state{running, exited},name}
docker ps
- Manage the container
Once we have container we can stop/start/restart it using its id
docker stop [container_id]
docker restart [contaier_id]
docker start [container_id]
How to Run a Docker-Compose Project
- Build the image(s)
docker-compose up -d --build
# -d = detached background
# --build = build images
docker-compose ps
# Lists containers and their state
- Managing docker-compose
docker-compose stop
docker-compose start
docker-compose restart
- Remove docker-compose containers and their contents
- Stops containers and removes containers, networks, volumes, and images created by
up
.
- Stops containers and removes containers, networks, volumes, and images created by
docker-compose down